package wonder.com.chinaerweima.Wedge;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import wonder.com.chinaerweima.R;

/**
 * Created by Administrator on 2016/6/12.
 */
public class FooterNavBar extends LinearLayout {
    private Context context;
    private Drawable FirstItemIconDrawable ,secondItemIconDrawable ,
            thirdItemIconDrawable , fourthItemIconDrawable ;

    private String firstItemText,secondItemText,thirdItemText,fourthItemText;
    private CustomFontTextView firstItem,secondItem,thirdItem,fourthItem;
    private  int iconTextPadding,itemTextColor;
    private float itemTextSize;
    private String itemTextFontPathInAssets;
    private CustomFontTextView[] items;


    public FooterNavBar(Context context) {
        this(context,null);
    }

    public FooterNavBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FooterNavBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
        getAttrs(attrs);
        findView();
   initView();
    }
    private void getAttrs(AttributeSet attributeSet){
       TypedArray ta= context.obtainStyledAttributes(attributeSet,R.styleable.FooterNavBar);
        FirstItemIconDrawable=ta.getDrawable(R.styleable.FooterNavBar_firstItemIconDrawable);
        secondItemIconDrawable=ta.getDrawable(R.styleable.FooterNavBar_secondItemIconDrawable);
        thirdItemIconDrawable=ta.getDrawable(R.styleable.FooterNavBar_thirdItemIconDrawable);
        fourthItemIconDrawable=ta.getDrawable(R.styleable.FooterNavBar_fourthItemIconDrawable);
        firstItemText = ta.getString(R.styleable.FooterNavBar_firstItemText);
        secondItemText=ta.getString(R.styleable.FooterNavBar_secondItemText);
        thirdItemText=ta.getString(R.styleable.FooterNavBar_thirdItemText);
        fourthItemText=ta.getString(R.styleable.FooterNavBar_fourthItemText);
        iconTextPadding=ta.getDimensionPixelSize(R.styleable.FooterNavBar_iconTextPadding,1);
        itemTextColor=  ta.getColor(R.styleable.FooterNavBar_itemTextColor, Color.WHITE);
        itemTextSize=  ta.getDimension(R.styleable.FooterNavBar_itemTextSize,0f);
        itemTextFontPathInAssets=ta.getString(R.styleable.FooterNavBar_itemTextFontPathInAssets);
        ta.recycle();
    }
    private void findView(){
        View view= LayoutInflater.from(context).inflate(R.layout.activity_footer_navbar,this);
        firstItem=(CustomFontTextView) view.findViewById(R.id.footer_nav_bar_1);
        secondItem=(CustomFontTextView) view.findViewById(R.id.footer_nav_bar_2);
        thirdItem=(CustomFontTextView) view.findViewById(R.id.footer_nav_bar_3);
        fourthItem=(CustomFontTextView) view.findViewById(R.id.footer_nav_bar_4);
        items=new CustomFontTextView[]{firstItem,secondItem,thirdItem,fourthItem};
    }
private void initView(){
    if (itemTextFontPathInAssets!=null){
        try {
            Typeface tf=Typeface.createFromAsset(context.getAssets(),itemTextFontPathInAssets)
       firstItem.setTypeface(tf);
       secondItem.setTypeface(tf);
      thirdItem.setTypeface(tf);
      fourthItem.setTypeface(tf);}
catch(Exception e){}
        FirstItemIconDrawable.setBounds(0,0,FirstItemIconDrawable.getMinimumWidth(),FirstItemIconDrawable.getMinimumHeight());
        secondItemIconDrawable.setBounds(0,0,secondItemIconDrawable.getMinimumWidth(),secondItemIconDrawable.getMinimumHeight());
        thirdItemIconDrawable.setBounds(0,0,thirdItemIconDrawable.getMinimumWidth(),thirdItemIconDrawable.getMinimumHeight());
        fourthItemIconDrawable.setBounds(0,0,fourthItemIconDrawable.getMinimumWidth(),fourthItemIconDrawable.getMinimumHeight());
        //手工设置文本与图片相对位置时 左上右下
       firstItem.setCompoundDrawables(null,FirstItemIconDrawable,null,null);
        secondItem.setCompoundDrawables(null,secondItemIconDrawable,null,null);
        thirdItem.setCompoundDrawables(null,thirdItemIconDrawable,null,null);
        fourthItem.setCompoundDrawables(null,fourthItemIconDrawable,null,null);
//        设置文本与图片padding
        firstItem.setCompoundDrawablePadding(iconTextPadding);
        secondItem.setCompoundDrawablePadding(iconTextPadding);
        thirdItem.setCompoundDrawablePadding(iconTextPadding);
        fourthItem.setCompoundDrawablePadding(iconTextPadding);
//设置文字
        firstItem.setText(firstItemText);
        secondItem.setText(secondItemText);
        thirdItem.setText(thirdItemText);
        fourthItem.setText(fourthItemText);
//        设置字体颜色
        firstItem.setTextColor(itemTextColor);
        secondItem.setTextColor(itemTextColor);
        thirdItem.setTextColor(itemTextColor);
        fourthItem.setTextColor(itemTextColor);
//设置字体大小
        firstItem.setTextSize(itemTextSize);
        secondItem.setTextSize(itemTextSize);
        thirdItem.setTextSize(itemTextSize);
        fourthItem.setTextSize(itemTextSize);

        firstItem.setOnClickListener(onClickListener);
        OnClickListener onClickListener=new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        };
    }
}

}
